package com.xiaoyi.springboot.config.rabbitmq;


import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.List;
/**
 * rabbitmq 配置文件
 * @author xiaoyi
 * @date 2021/10/10 22:31
 * @version v1.0
 */
@Primary
@Component
@ConfigurationProperties(
        prefix = "spring.rabbitmq"
)
public class RabbitMqProperties extends RabbitProperties {
    private boolean enable;
    private boolean durable = true;
    private boolean autoDelete = false;
    private List<TemplateBinding> templateBindings;

    public RabbitMqProperties() {
    }

    public boolean isEnable() {
        return this.enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public boolean isDurable() {
        return this.durable;
    }

    public void setDurable(boolean durable) {
        this.durable = durable;
    }

    public boolean isAutoDelete() {
        return this.autoDelete;
    }

    public void setAutoDelete(boolean autoDelete) {
        this.autoDelete = autoDelete;
    }

    public List<TemplateBinding> getTemplateBindings() {
        return this.templateBindings;
    }

    public void setTemplateBindings(List<TemplateBinding> templateBindings) {
        this.templateBindings = templateBindings;
    }

    public static enum TemplateBindingType {
        DIRECT,
        TOPIC,
        FANOUT,
        HEADERS,
        SYSTEM;

        private TemplateBindingType() {
        }
    }

    public static class TemplateBinding {
        private RabbitMqProperties.TemplateBindingType type;
        private String exchange;
        private String queue;
        private String routeKey;

        public TemplateBinding() {
        }

        public RabbitMqProperties.TemplateBindingType getType() {
            return this.type;
        }

        public void setType(RabbitMqProperties.TemplateBindingType type) {
            this.type = type;
        }

        public String getExchange() {
            return this.exchange;
        }

        public void setExchange(String exchange) {
            this.exchange = exchange;
        }

        public String getQueue() {
            return this.queue;
        }

        public void setQueue(String queue) {
            this.queue = queue;
        }

        public String getRouteKey() {
            return this.routeKey;
        }

        public void setRouteKey(String routeKey) {
            this.routeKey = routeKey;
        }
    }
}
